package org.intellij.lang.assembly.parsing;

import com.intellij.ide.highlighter.custom.tokens.BaseTokenParser;
import com.intellij.psi.CustomHighlighterTokenType;

/**
 * @author weijiancai
 * @version 1.0
 * @DateTime 2010-11-18 19:55:23
 */
public class SuffixedHexNumberParser extends BaseTokenParser {

    public final boolean hasToken(int position) {
        final int start = position;
        final char startChar = myBuffer.charAt(start);
        if(!isHexDigit(startChar)) return false;
        for (position++; position < myEndOffset; position++) {
            if (!isHexDigit(myBuffer.charAt(position))) break;
        }
        if (position == myEndOffset) {
            return false;
        }
        if (myBuffer.charAt(position) == 'h' || myBuffer.charAt(position) == 'H') {
            if ((startChar >= 'a' && startChar <= 'f') || (startChar >= 'A' && startChar <= 'F')) {
                return false;
            }
            myTokenInfo.updateData(start, position, CustomHighlighterTokenType.NUMBER);
            return true;
        }

        return false;
    }

    public int getSmartUpdateShift() {
        return 0;
    }

    public static boolean isHexDigit(char c) {
        return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
    }
}
